package bma.common.langutil.log;

import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;

/**
 * Logback的工具类
 * 
 * @author 关中
 * @since 1.0 (imported from BMA.ESP Project)
 * 
 */
public class LogbackUtil {

	public static Level getLevel(String type) {
		LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
		ch.qos.logback.classic.Logger log = lc.getLogger(type);
		if (log != null) {
			return log.getLevel();
		}
		return null;
	}

	public static void setLevel(String type, String level) {
		LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
		ch.qos.logback.classic.Logger log = lc.getLogger(type);
		if (log != null) {
			if (level == null) {
				log.setLevel(null);
			} else {
				log.setLevel(Level.valueOf(level.toUpperCase()));
			}
		}
	}
}
